from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-11-04 14:02:18.353096
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 04, Nov, 2022
Time: 14:02:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8651
Nobs: 830.000 HQIC: -51.1807
Log likelihood: 10812.0 FPE: 4.86672e-23
AIC: -51.3770 Det(Omega_mle): 4.36944e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.297171 0.051120 5.813 0.000
L1.Burgenland 0.109100 0.035007 3.116 0.002
L1.Kärnten -0.106366 0.018643 -5.705 0.000
L1.Niederösterreich 0.209779 0.073221 2.865 0.004
L1.Oberösterreich 0.101552 0.069731 1.456 0.145
L1.Salzburg 0.249997 0.037188 6.723 0.000
L1.Steiermark 0.036079 0.048748 0.740 0.459
L1.Tirol 0.105900 0.039496 2.681 0.007
L1.Vorarlberg -0.058692 0.034032 -1.725 0.085
L1.Wien 0.059849 0.062626 0.956 0.339
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.068414 0.105550 0.648 0.517
L1.Burgenland -0.031883 0.072282 -0.441 0.659
L1.Kärnten 0.047426 0.038494 1.232 0.218
L1.Niederösterreich -0.172746 0.151183 -1.143 0.253
L1.Oberösterreich 0.378513 0.143978 2.629 0.009
L1.Salzburg 0.287578 0.076784 3.745 0.000
L1.Steiermark 0.106096 0.100653 1.054 0.292
L1.Tirol 0.314888 0.081550 3.861 0.000
L1.Vorarlberg 0.023811 0.070268 0.339 0.735
L1.Wien -0.015433 0.129308 -0.119 0.905
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194339 0.026388 7.365 0.000
L1.Burgenland 0.091772 0.018071 5.078 0.000
L1.Kärnten -0.008748 0.009624 -0.909 0.363
L1.Niederösterreich 0.265873 0.037797 7.034 0.000
L1.Oberösterreich 0.117050 0.035995 3.252 0.001
L1.Salzburg 0.050482 0.019196 2.630 0.009
L1.Steiermark 0.017445 0.025164 0.693 0.488
L1.Tirol 0.096222 0.020388 4.720 0.000
L1.Vorarlberg 0.057819 0.017567 3.291 0.001
L1.Wien 0.118830 0.032328 3.676 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.105206 0.027043 3.890 0.000
L1.Burgenland 0.046349 0.018520 2.503 0.012
L1.Kärnten -0.017107 0.009862 -1.735 0.083
L1.Niederösterreich 0.195927 0.038735 5.058 0.000
L1.Oberösterreich 0.282639 0.036889 7.662 0.000
L1.Salzburg 0.118817 0.019673 6.040 0.000
L1.Steiermark 0.102252 0.025788 3.965 0.000
L1.Tirol 0.120984 0.020894 5.790 0.000
L1.Vorarlberg 0.070167 0.018003 3.897 0.000
L1.Wien -0.025881 0.033130 -0.781 0.435
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128071 0.049160 2.605 0.009
L1.Burgenland -0.049804 0.033665 -1.479 0.139
L1.Kärnten -0.039812 0.017928 -2.221 0.026
L1.Niederösterreich 0.165565 0.070414 2.351 0.019
L1.Oberösterreich 0.140443 0.067058 2.094 0.036
L1.Salzburg 0.284031 0.035762 7.942 0.000
L1.Steiermark 0.033678 0.046879 0.718 0.473
L1.Tirol 0.163215 0.037982 4.297 0.000
L1.Vorarlberg 0.105000 0.032727 3.208 0.001
L1.Wien 0.071357 0.060225 1.185 0.236
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059693 0.038817 1.538 0.124
L1.Burgenland 0.041042 0.026582 1.544 0.123
L1.Kärnten 0.049764 0.014156 3.515 0.000
L1.Niederösterreich 0.226892 0.055599 4.081 0.000
L1.Oberösterreich 0.272848 0.052949 5.153 0.000
L1.Salzburg 0.055717 0.028238 1.973 0.048
L1.Steiermark -0.007736 0.037016 -0.209 0.834
L1.Tirol 0.153833 0.029991 5.129 0.000
L1.Vorarlberg 0.069674 0.025842 2.696 0.007
L1.Wien 0.079117 0.047554 1.664 0.096
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180139 0.046541 3.871 0.000
L1.Burgenland -0.004731 0.031872 -0.148 0.882
L1.Kärnten -0.060968 0.016973 -3.592 0.000
L1.Niederösterreich -0.085449 0.066663 -1.282 0.200
L1.Oberösterreich 0.191013 0.063486 3.009 0.003
L1.Salzburg 0.058750 0.033857 1.735 0.083
L1.Steiermark 0.228124 0.044382 5.140 0.000
L1.Tirol 0.493994 0.035958 13.738 0.000
L1.Vorarlberg 0.049247 0.030984 1.589 0.112
L1.Wien -0.048203 0.057017 -0.845 0.398
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.155462 0.053031 2.932 0.003
L1.Burgenland -0.009954 0.036316 -0.274 0.784
L1.Kärnten 0.065110 0.019340 3.367 0.001
L1.Niederösterreich 0.201404 0.075958 2.652 0.008
L1.Oberösterreich -0.067816 0.072338 -0.937 0.349
L1.Salzburg 0.220647 0.038578 5.719 0.000
L1.Steiermark 0.115422 0.050570 2.282 0.022
L1.Tirol 0.081258 0.040972 1.983 0.047
L1.Vorarlberg 0.124283 0.035304 3.520 0.000
L1.Wien 0.115829 0.064967 1.783 0.075
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.352639 0.031034 11.363 0.000
L1.Burgenland 0.007585 0.021253 0.357 0.721
L1.Kärnten -0.024329 0.011318 -2.150 0.032
L1.Niederösterreich 0.226526 0.044451 5.096 0.000
L1.Oberösterreich 0.164030 0.042333 3.875 0.000
L1.Salzburg 0.050966 0.022576 2.258 0.024
L1.Steiermark -0.015731 0.029594 -0.532 0.595
L1.Tirol 0.112988 0.023977 4.712 0.000
L1.Vorarlberg 0.073149 0.020660 3.541 0.000
L1.Wien 0.053276 0.038020 1.401 0.161
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.043079 0.157730 0.190787 0.165202 0.128997 0.122446 0.068452 0.229321
Kärnten 0.043079 1.000000 0.000805 0.131487 0.044638 0.098339 0.428248 -0.051246 0.102385
Niederösterreich 0.157730 0.000805 1.000000 0.342698 0.164478 0.308364 0.124255 0.189054 0.336170
Oberösterreich 0.190787 0.131487 0.342698 1.000000 0.234639 0.337715 0.177376 0.178268 0.269968
Salzburg 0.165202 0.044638 0.164478 0.234639 1.000000 0.152553 0.143294 0.152346 0.140082
Steiermark 0.128997 0.098339 0.308364 0.337715 0.152553 1.000000 0.162109 0.146357 0.088240
Tirol 0.122446 0.428248 0.124255 0.177376 0.143294 0.162109 1.000000 0.120411 0.162525
Vorarlberg 0.068452 -0.051246 0.189054 0.178268 0.152346 0.146357 0.120411 1.000000 0.013382
Wien 0.229321 0.102385 0.336170 0.269968 0.140082 0.088240 0.162525 0.013382 1.000000